<template>
  <el-dialog :title="titles" :visible.sync="opens" width="1300px" append-to-body :before-close="close">
    <el-table :data="lists" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column
        v-if="pickWholeOutBtn"
        type="selection"
        width="55"
        :selectable="selectable"
      />
      <el-table-column prop="goods_name" label="商品名称" align="center" />
      <el-table-column prop="number" label="出库数量" align="center" width="100" />
      <el-table-column prop="status" label="出库状态" align="center" width="100">

        <template v-slot="scope">
          {{ scope.row.status == 0 ? '未出库' : '已出库' }}
        </template>

      </el-table-column>
      <el-table-column prop="config_full_name" label="库位" align="center" />
<!--      <el-table-column prop="tray_id" label="托盘码" align="center" />-->
<!--      <el-table-column prop="box_id" label="箱号" align="center" />-->
<!--      <el-table-column prop="slice_id" label="片号" align="center" />-->
<!--      <el-table-column prop="LOT1" label="LOT1" align="center" />-->
<!--      <el-table-column prop="LOT2" label="LOT2" align="center" />-->
<!--      <el-table-column prop="LOT3" label="LOT3" align="center" />-->
      <el-table-column prop="finNum" label="sn码" align="center" sortable >
        <template v-slot="scope">
          {{ scope.row.sn }}
        </template>
      </el-table-column>
      <!--      <el-table-column prop="created_at" label="入库时间" align="center" />-->
      <el-table-column prop="dictionary_name" label="包装(数量/单位)" align="center" width="120">
        <template v-slot="scope">
          {{ scope.row.packing_num+'/'+ scope.row.unit_name }}
        </template>
      </el-table-column>
      <!--      <el-table-column prop="config_name" label="项号" align="center" />-->
      <!--      <el-table-column prop="customer_business_number" label="客户业务单号" align="center" />-->
      <!--      <el-table-column prop="warehousing_id" label="入库编号" align="center" />-->

    </el-table>
    <div style="margin-top: 20px">
      <el-button v-if="pickWholeOutBtn" type="danger" :disabled="!ids.length" @click="pickWholeOut">出库</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { pickWholeOut } from '@/api/stock'
import { inventoryOperationRecordList } from '@/api/storehouse'

export default {
  name: 'AddEdit',
  props: {
    opens: {
      type: Boolean
    },
    lists: {
      type: Array
    },
    titles: {
      type: String
    },
    outsonid: {
      type: [String, Number]
    }
  },
  data() {
    return {
      ids: []
    }
  },
  computed: {
    pickWholeOutBtn() {
      return this.lists.some(item => item.status === '0')
    }
  },
  watch: {
    lists(val) {
      val.forEach(item => {
        item.number = item.number + '(' + item.stock_status + ')'
      })
    }
  },
  created() {
  },
  methods: {
    close() {
      this.$emit('update:opens', false)
    },
    selectable(row, rowIndex) {
      if (row.status === '1') {
        return false // 禁用
      } else {
        return true // 不禁用
      }
    },
    /** 选中的项 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    pickWholeOut() {
      const that = this

      that.$confirm('确定要将选中的捡货单全部出库, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await pickWholeOut({
          'ids': that.ids,
          'warehouse_out_son_id': that.outsonid
        })
        that.$parent.seeInfo({ warehouse_out_son_id: that.outsonid })
        that.$message({
          type: 'success',
          message: '出库成功!'
        })
      })
    }
  }
}
</script>

